<template>
  <div class="carousel">
    <Carousel 
      :autoplay="setting.autoplay"
      :autoplay-speed="setting.autoplaySpeed"
      @on-change="getIndex"
    >
      <CarouselItem v-for="(item, index) in carouselList" :key="index">
        <a :href="item.href">
          <img :src="item.img"
          height="300">
        </a>
      </CarouselItem>
    </Carousel>
    <div class="shadow"></div> 
    <a class="description">{{carouselList[index].title}}</a>
  </div>
</template>

<script>
export default {
  name: 'MyCarousel',
  data() {
    return {
      setting: {
        autoplay: true,
        autoplaySpeed: 7000,
      },
      index: 0
    }
  },
  computed: {
    carouselList() {
      return this.$store.getters['blog/carousels']
    }
  },
  methods: {
    getIndex(oldValue, value) {
      this.index = value
    }
  },
}
</script>

<style lang='scss'>
.ivu-carousel-item {
  img {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
  }
}
</style>
<style lang='scss' scope>
.carousel {
  position: relative;
  margin: 1rem;
  .shadow{
    position: absolute;
    width: 100%;
    height: 30px;
    bottom: 5px;
    background: #000;
    opacity: 0.4;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
  }
  .description {
    position: absolute;
    left: 0;
    bottom: 5px;
    width: 100%;
    padding: 0 10px;
    color: #fff;
    line-height: 30px;
  }
}
@media screen and (max-width: 992px) { 
  .carousel {
    margin: 0;
    .shadow {
      bottom: 0;
      height: 22px;
      border-radius: 0;
    }
    .description {
      bottom: 0;
      line-height: 22px;
      font-size: 12px;
    }
  }
  .ivu-carousel-item { 
    height: calc(100vw * 0.341) !important;
    img {
      border-radius: 0;
      height: calc(100vw * 0.341) !important;
    }
  }
}
</style>